<!-- 请求富文本 -->
<template>
	<loading-page v-if="data.loading" />
	<view class="content">
		<rich-text class="rich-text" :nodes="nodes"></rich-text>
	</view>
	<view class="footer">
		<view class="tort">侵权举报请联系 QQ：<text @click.stop="copy('2355583797')">2355583797 </text> TEL：<text @click.stop="call('18428362892')">18428362892</text></view>
		<view class="copyright">© 2010-2022 | m.book118.com 原创力文档. All Rights Reserved</view>
		<view class="beian">四川文动网络科技有限公司 | <text>蜀ICP备08101938号-1</text></view>
	</view>
</template>
<script setup>
	import { ref, reactive, computed } from 'vue';
	import { onLoad } from '@dcloudio/uni-app';
	import htmlParser from '@/subpages/common/utils/html-parser.js';
	import { showCopy } from '@/common/hooks/useShow.js';
	import { merchantAgreement } from '@/subpages/common/api/richtext.js';
	onLoad((options) => {
		data.type = options.type ? options.type : 'merchantAgreement';
		init();
	});
	const nodes = computed(() => {
		return htmlParser(data.content);
	});
	const data = reactive({
		type: null,
		loading: true,
		content: ''
	});
	// 初始化
	async function init() {
		let res;
		switch (data.type) {
			case 'merchantAgreement':
				res = await merchantAgreement();
				uni.setNavigationBarTitle({
					title: '商户服务协议'
				})
				break;
			default:
				break;
		}
		data.content = res.data.agreement;
		data.loading = false;
	}
	// 复制
	function copy(value) {
		showCopy({
			data: value,
			type: 1,
			icon: 'none',
			title: `QQ已复制`
		})
	}
	// 打电话
	function call(num) {
		uni.makePhoneCall({
			phoneNumber: num,
			fail() {}
		});
	}
</script>
<style></style>
<style scoped lang="scss">
	.content {
		padding: 0 28rpx;
	}
	.rich-text {
		font-size: 30rpx;
	}
	.footer {
		padding: 30rpx 0;
		background-color: #F2F5F9;
		.tort,
		.copyright,
		.beian {
			text-align: center;
			line-height: 40rpx;
			font-size: 24rpx;
			color: #999;
		}
		.tort text,
		.copyright text,
		.beian text {
			display: inline-block;
			font-size: 24rpx;
			color: #999;
		}
	}
</style>
